<template>
  <div>
    <el-container>
      <el-header
        >欢迎-请先登录
        <el-link :underline="false" href="#/AddZhuCe" id="a">注册</el-link>
      </el-header>
      <el-main>
        <div id="beg">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="用户名" prop="admin" style="margin-top: 20px">
              <el-input
                v-model="ruleForm.admin"
                style="width: 200px"
              ></el-input>
            </el-form-item>

            <el-form-item label="密码" prop="pwd">
              <el-input v-model="ruleForm.pwd" style="width: 200px"></el-input>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')"
                >立即登录</el-button
              >
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        admin: "",
        pwd: "",
      },
      rules: {
        admin: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios
            .get(
              "https://localhost:44353/api/LoginAPI/LoginUsers?admin=" +
                this.ruleForm.admin +
                "&pwd=" +
                this.ruleForm.pwd +
                ""
            )
            .then((res) => {
              if (res.data != null) {
                this.$message({
                  showClose: true,
                  message: "恭喜你，登陆成功",
                  type: "success",
                });
                this.$router.push("/main");
              } else {
                this.$message({
                  showClose: true,
                  message: "错了哦，请检查用户名或密码",
                  type: "error",
                });
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: left;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
#beg {
  margin-left: auto;
  margin-right: auto;
  width: 350px;
  height: 200px;
  border-style: double;
}
#a {
  margin-right: 30px;
  margin-top: 15px;
  float: right;
  font-size: 25px;
}
</style>